<!-- 预警详情 -->
<template>
	<view class="page">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block style="color: ##777777;font-size: 32rpx;" slot="content">预警详情</block>
		</cu-custom>
		<view class="content-xq">
			<ul>
				<li>
					<view class="list-box" style="padding: 0;font-size: 12px;">
						<p class="list-info">预警名称：</p>
						<p class="list-title">{{ title || '暂无' }}</p>
					</view>
				</li>
				<li>
					<text class="list-info">预警设备：</text>
					<text class="list-title">{{ yjry || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">上报时间：</text>
					<text class="list-title">{{ time || '暂无'}}</text>
				</li>
				<li>
					<text class="list-info">业主名称：</text>
					<text class="list-title">{{ yzmc || '暂无'}}</text>
				</li>
				<li>
					<view class="list-box" style="padding: 0;font-size: 12px;line-height: 94rpx;">
						<p class="list-info" >预警信息：</p>
						<p class="list-title">{{ info }}</p>
					</view>
				</li>
				<li>
					<text class="list-info">所属区域：</text>
					<text class="list-title">{{ address | strFormat }}</text>
				</li>
			</ul>
		</view>

		<view v-if="feedtype == -1" class="flex btns-group">
			<button class="my-btn-grpup" @click="tjjshq">设备误报</button>
			<button class="my-btn-grpup" @click="qrhq">确认火情</button>
		</view>
		<message />
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import * as constants from '@/common/config.js';
export default {
	onLoad(option) {
		this.ucId = option.ucId
		this.noticeInfoId = option.noticeInfoId
		// 封装参数
		let params = {
			"ucId": option.ucId
		}
		let that = this
		// 请求数据
		let app = getApp()
		app.globalData.request({
			url: '/wx/fireAlarmInfo/getInFireAlarmInfoVo',
			data: {
				...params
			}
		}).then(function (res) {
			console.info(res)

			that.title = res.data.data.name
			that.yjry = res.data.data.equipmentName
			that.time = res.data.data.alarmTime
			that.yzmc = res.data.data.enterpriseName
			that.info = res.data.data.alarmInfo
			that.address = res.data.data.location

			that.ucId = res.data.data.ucId
			that.feedtype = res.data.data.feedtype
			that.equipmentId = res.data.data.equipmentId
		}).catch(function (e) {

		})
	},
	data() {
		return {
			title: '',
			yjry: '',
			time: '',
			yzmc: '',
			info: '',
			address: '',
			ucId: '',
			feedtype: '',
			equipmentId: '',
			videoPath: '',
			videoServerPath: '',
			noticeInfoId: '',
			imgUrl: ''
		}
	},
	methods: {
		uploadFile(path) {
			let that = this
			let app = getApp()
			let token = app.globalData.getToken('authorization')
			const uploadTask = uni.uploadFile({
				url: constants.API + 'wx/common/upload',
				filePath: path,
				header: {
					"authorization": token
				},
				name: 'file',
				success(uploadFileRes) {
					let obj = JSON.parse(uploadFileRes.data)
					that.imgUrl = obj.data;
					that.sbwb()
				}
			})
		},
		tjjshq() {
			// 首先拍照片
			let that = this
			uni.chooseImage({
				count: 4, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['camera'], //从相册选择
				success: (res) => {
					let path = res.tempFilePaths
					// 上传
					this.uploadFile(path[0]);
				}
			})
		},
		sbwb() {
			let that = this
			let params = {
				ucId: this.ucId,
				feedtype: 0,
				feedback: "设备误报",
				fileUrl: this.imgUrl
			}
			// 生成报警信息
			let app = getApp()
			app.globalData.request({
				url: '/wx/fireAlarmInfo/updateInFireAlarmInfo',
				data: params
			}).then(function (res) {
				that.$refs.uToast.show({
					message: "上传误报成功",
					type: 'success',
					complete() {
						uni.navigateBack({
							delta: 1
						})
					}
				})

			}).catch(function (e) { })

		},
		getTempFilePath(url, types) {
			uni.showLoading({
				title: '保存中...'
			});
			// 如果已经下载本地路径，那么直接储存
			let obj = {
				filePath: url,
				success: () => {
					uni.showModal({
						content: '保存成功',
						showCancel: false
					});
					uni.hideLoading();
				},
				fail: e => {
					uni.hideLoading();
					uni.showModal({
						content: '保存失败',
						showCancel: false
					});
				}
			};

			if (types === 'videoTempPath') {
				uni.saveVideoToPhotosAlbum(obj);
			} else {
				uni.saveImageToPhotosAlbum(obj);
			}
		},
		qrhq() {

			// 确认火情之后要  录制视频  确认火情报警接口
			// 报警成功 页面。。。。
			// 结束火情，弹框提醒。确认之后拍照接口。。。
			// 首先拍照片
			let that = this
			uni.chooseVideo({
				count: 1,
				maxDuration: 15,
				sourceType: ['camera'],
				success: res => {
					that.videoPath = res.tempFilePath;
					// 上传
					let app = getApp()
					let token = app.globalData.getToken('authorization')
					uni.uploadFile({
						url: constants.API + 'wx/common/upload',
						filePath: that.videoPath,
						header: {
							"authorization": token
						},
						name: 'file',
						success: (uploadFileRes) => {

							that.videoServerPath = JSON.parse(uploadFileRes.data).data
							// 确认火情
							let params = {
								ucId: that.ucId,
								equipmentId: that.equipmentId,
								alarmInfoId: that.ucId,
								drill: 0,
								fireVodie: that.videoServerPath
							}
							let app = getApp()
							app.globalData.request({
								url: 'wx/firealarm/equipmentFireNotice',
								data: {
									...params
								}
							}).then(function (res) {
								let data = res.data.code
								if (data == 0) {
									uni.navigateTo({
										url: '../bjcg/bjcg?noticeId=' + res.data.data.noticeId + '&fireInfoId=' + res.data.data.fireInfoId + '&audioId=1'
									})

								} else {
									uni.showToast({
										title: "确认火情失败",
										icon: 'error'
									})
								}
							}).catch(function (e) {
								uni.showToast({
									title: "操作失败",
									icon: 'error'
								})
							})
						}
					});
				}
			})
		}
	}
}
</script>

<style scoped>
</style>
